//
//  KLMessageTableViewController.m
//  KISSLOCK
//
//  Created by 陈宾鹏 on 16/9/22.
//  Copyright © 2016年 陈宾鹏. All rights reserved.
//

#import "KLMessageTableViewController.h"
#import "KLHelp.h"
#import "KLHttpAPI.h"
#import "HemaConst.h"
#import "Masonry.h"

@interface KLMessageTableViewController ()

@end

@implementation KLMessageTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self naveSet];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"message"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    //分割线
    UIView *seprateLine = [[UIView alloc]init];
    seprateLine.backgroundColor = [UIColor darkGrayColor];
    seprateLine.alpha = 0.2;
    [cell.contentView addSubview:seprateLine];
    [seprateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(UI_View_Width);
        make.height.mas_equalTo(0.2);
        make.bottom.equalTo(cell.contentView);
        make.left.mas_equalTo(0);
    }];
    //主标题和副标题
    UIImage *icon;
    if(indexPath.row == 0){
        icon = [UIImage imageNamed:@"个人消息"];
        cell.textLabel.text = @"个人消息";
        cell.detailTextLabel.text = @"及时查看系统给您发送的重要消息";
    }else if (indexPath.row == 1){
        icon = [UIImage imageNamed:@"账单消息"];
        cell.textLabel.text = @"账单消息";
        cell.detailTextLabel.text = @"补贴返现、分享返现、退款消息，点这里";
    }else if(indexPath.row == 2){
        icon = [UIImage imageNamed:@"系统消息"];
        cell.textLabel.text = @"系统消息";
        cell.detailTextLabel.text = @"及时查看最新官方消息在这里";
    }
    cell.textLabel.alpha = 0.6;
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.detailTextLabel.alpha = 0.4;
    //图片
    CGSize itemSize = CGSizeMake(35, 35);
    UIGraphicsBeginImageContextWithOptions(itemSize, NO ,0.0);
    CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
    [icon drawInRect:imageRect];
    cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    cell.imageView.layer.masksToBounds = YES;
    cell.imageView.layer.cornerRadius = 17.5;
    //小红点
    UIImageView *redPoint = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"红点图标"]];
    [cell.contentView addSubview:redPoint];
    redPoint.layer.masksToBounds = YES;
    redPoint.layer.cornerRadius = 4;
    [redPoint mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(8);
        make.width.mas_equalTo(8);
        make.top.equalTo(cell.imageView).with.offset(-2);
        make.right.equalTo(cell.imageView).with.offset(2);
    }];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 65;
}

#pragma mark -界面设置
//初始化导航栏
-(void)naveSet{
    self.navigationController.navigationBarHidden = NO;
    self.title = @"消息中心";
    self.view.backgroundColor = RGB_UI_COLOR(250, 250, 250);
    self.tableView.tableFooterView = [[UIView alloc]init];
    
    [KLHelp navSet:self doBackHandeler:^(UIButton *backButton) {
        [backButton addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    }];
}-(void)doBack:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
